/*
 * @Author: 孙文豪
 * @Description: 
 * @Date: 2024-03-04 14:41:47
 * @LastEditTime: 2024-03-05 17:48:34
 * @LastEditors: 孙文豪
 */
import { createRouter, createWebHashHistory } from 'vue-router'


const routes = [
    {
        path: '/login',
        name: 'login',
        component: () => import('../pages/Login/Login.vue'),   //登录
    },
    {
        path: '/',
        name: 'main',
        component: () => import('../pages/Main/Main.vue'),   //主页
        redirect: '/statistics',
        children: [
            {
                path: '/statistics',
                name: 'statistics',
                component: () => import('../pages/Main/subpages/Statistics/Statistics.vue'),
            },
            {
                // 销售管理
                path: '/sale',
                name: 'sale',
                component: () => import('../pages/Main/subpages/sale/sale.vue'),
            },
            {
                // 进货管理
                path: '/stock',
                name: 'stock',
                component: () => import('../pages/Main/subpages/stock/stock.vue'),
            },
            {
                // 库存管理
                path: '/customer',
                name: 'customer',
                component: () => import('../pages/Main/subpages/customer/customer.vue'),
            },
            {
                // 商品信息
                path: '/commodity',
                name: 'commodity',
                component: () => import('../pages/Main/subpages/commodity/commodity.vue'),
            },
        ]
    },
]


const router = createRouter({
    history: createWebHashHistory(),
    routes
})
router.beforeEach((to, from, next) => {
    const LoginStatus = localStorage.getItem('LoginStatus');
    if (to.path === '/login' || LoginStatus) {
        next();
    } else {
        next('/login');  //您还没有登录，请先登录
    }
})
export default router